package com.shop.test;

import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.shop.dao.EmpMapper;
import com.shop.entity.Emp;
import com.shop.util.MyBatisUtil;

public class MyBatisTest1 {
	

	
	
	@Test
	public void test3() throws IOException{
		SqlSession session = MyBatisUtil.getSqlSession();
		EmpMapper empMapper = session.getMapper(EmpMapper.class); 
		List<Emp> list = empMapper.searchEmps(Arrays.asList(1,2,4));
		for (Emp emp : list) {
			System.out.println(emp);
		}
		MyBatisUtil.closesSession(session);
	}
	
	
	@Test
	public void test2() throws IOException{
		SqlSession session = MyBatisUtil.getSqlSession();
		EmpMapper empMapper = session.getMapper(EmpMapper.class); 
		Emp e = new Emp();
		e.setEname("胖迪");
//		e.setJob("总舵主");
//		e.setSal(6666d);
		e.setHiredate(new Date());
		e.setId(1);
		Integer num = empMapper.updateEmp(e);
		System.out.println("受影响的行数:"+num);
		session.commit();
		MyBatisUtil.closesSession(session);
	}
	@Test
	public void test1() throws IOException{
		SqlSession session = MyBatisUtil.getSqlSession();
		EmpMapper empMapper = session.getMapper(EmpMapper.class); 
		Emp e = new Emp();
		//e.setEname("%张%");
		e.setJob("真人");
		List<Emp> list = empMapper.searchEmp(e);
		for (Emp emp : list) {
			System.out.println(emp);
		}
		MyBatisUtil.closesSession(session);
	}
	
}
